<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>出库管理</title>
<!-- 导入jquery核心类库 -->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- 导入easyui类库 -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/ext/portal.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/css/default.css">	
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.portal.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.cookie.js"></script>
<script
	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"
	type="text/javascript"></script>

<script type="text/javascript">
function doAdd(){
	//alert("增加...");
	//$("input[name='sId']").val('-1');
	$('#addStandardWindow').form('clear');
	$('#addStandardWindow *').trigger('blur');// 离焦
	$('#addStandardWindow').window("open").window('setTitle', '添加销售员');
	$("input[name='sId']").val('-1');
}

function getQueryParams(queryParams) {  
	var searchcontent_sn = $('#searchcontent_sn').val();
	var searchcontent_mac = $('#searchcontent_mac').val();
	var searchcontent_startdate = $('#searchcontent_startdate').datebox("getValue");
	var searchcontent_enddate = $('#searchcontent_enddate').datebox("getValue");
     queryParams.rsn = searchcontent_sn;  
     queryParams.rMac = searchcontent_mac;  
     queryParams.startdate = searchcontent_startdate;  
     queryParams.enddate = searchcontent_enddate;  
     return queryParams;  
   
 }  

 //增加查询参数，重新加载表格  
function loadgrid() {  
    //查询参数直接添加在queryParams中      
    var queryParams = $('#grid').datagrid('options').queryParams;  
    $('#grid').datagrid('options').queryParams =  getQueryParams(queryParams);
    $("#grid").datagrid('load');  
}  
 
function doSearch(){
	loadgrid();
}

function doReset(){
	$('input').val(null);
	loadgrid();
}


function doEdit(){
	var rowData = $('#grid').datagrid('getSelected');  
    
    if (rowData == null) {  
        $.messager.alert("提示", "请选择要修改的行！", "info");  
    } else{
        $("input[name='sId']").val(rowData.sId);
		$("input[name='sName']").val(rowData.sName);
		$("input[name='sEmail']").val(rowData.sEmail);
		$("input[name='sPhone']").val(rowData.sPhone);
		$('#sSex').combobox('setValues', rowData.sSex);
		$('#sStatus').combobox('setValues', rowData.sStatus);
		// 弹出窗口
		  
		$("#addStandardWindow").window('open').window('setTitle', '修改销售员');
    } 
}

function doOutput() {  
	
    // 返回被选中的行 然后集成的其实是 对象数组  
    var row = $('#grid').datagrid('getSelections'); 
    if (row.length== 0) {  
    	$.messager.alert("提示", "<br>请选择要出库的设备", "info");  
    }else{
    	 
	    var idString = "";  
	    var snString = "";  
	    for(var i = 0;i<row.length;i++){  
	    	if(row[i].rState==1){
    			$.messager.alert("提示", "<br>您选择了已出库的设备，请重新选择", "info");
    			return;
	    	}
	    	if(row[i].rState==2){
    			$.messager.alert("提示", "<br>您选择了正在申请SN的条目，请重新选择", "info");
    			return;
	    	}
	    
	    	idString += row[i].rId;  
	    	snString += row[i].rsn;  
	        if(i < row.length-1){  
	        	idString += ',';
	        	snString += ','; 
	        }else{  
	            break;  
	        }  
	    }  
    
   
		$('#outputWindow').window("open");
        $("textarea[name='sns']").val(snString);
        $("input[name='numbers']").val(row.length);
 
    }  
}


//定义列
var columns = [ [ 
/* { field:'ck',checkbox:true 
}, */ {
	field : 'rName',
	title : '产品名称',
	width : 120,
	/*align : 'center'*/
},{
	field : 'rsn',
	title : 'SN地址',
	width : 120,	
	/*align : 'center'*/
},{
	field : 'rState',
	title : '状态',  
	width : 80,
	/*align : 'center'*/
	formatter:formatterrState
	
},{
	field : 'rGoWhere',
	title : '流向',  
	width : 80,
	/*align : 'center'*/
	formatter:formatterrGoWhere
	
},{
	field : 'rVersion',
	title : '版本',
	width : 80,
	formatter:formatterrVersion
	/*align : 'center'*/
},{
	field : 'rColor',
	title : '颜色',
	width : 60,
	/*align : 'center'*/
},{
	field : 'rMac',
	title : 'MAC地址',
	width : 150,
	/*align : 'center'*/
},{
	field : 'rRukuTime',
	title : '入库时间',
	width : 120,
	/*align : 'center'*/
	formatter:formatterDate
}, {
	field : 'rId',
	title : '操作',
	width : 120,
	/*align : 'center'*/
	formatter:formaterCaozuo
}  ] ];


function formatterrSeller(value,row,index){
	if(value){
		return value.sName;
	}else{
		return;
	}
}

function formaterCaozuo(value,row,index){
	
	return "<a onclick=showDetails("+index+") href=#>详情</a>";

}

function showDetails(index){
    $('#grid').datagrid('selectRow',index);// 关键在这里  
    var row = $('#grid').datagrid('getSelected'); 
    if(row){ 
	    	//alert(row.iRId)
			location.href="${pageContext.request.contextPath}/page.rdetails.ashx?rId="+row.rId;

	}
}
function formatterDate(value,row,index){
	if(value==''||null==value){
		return '';
	}
	var now = new Date(parseInt(value) * 1000);  
	var year=now.getYear()+1900; 
	var month=now.getMonth()+1; 
	var date=now.getDate(); 
	var hour=now.getHours(); 
	var minute=now.getMinutes();
	minute= (minute > 9) ? minute=minute : minute='0'+minute;
	//var second=now.getSeconds(); 
	return year+"-"+month+"-"+date+" "+hour+":"+minute; 
}


function formatterrState(value,row,index){

	if(value==1){
		return "<font color='red'>出库</font>";
	}
	else if(value==0){
		return "库存";
	}else if(value==2){
		return "申请SN";
	}else if(value==3){
		return "已调试待入库";
	}else if(value==4){
		return "报废";
	}
}
function formatterrGoWhere(value) {
	if(value==0){
		return "员工自用";
	}else if(value==1){
		return "售出";
	}
}
function formatterrVersion(value,row,index){

	if(value==0){
		return "基础版";
	}
	else if(value==1){
		return "高定版";
	}else if(value==2){
		return "团装版";
	}else if(value==3){
		return "体验版";
	}
}

$(function(){
	$('#add').click(doAdd);
	$('#edit').click(doEdit);
	$('#search').click(doSearch);
	$('#reset').click(doReset);
	$('#outputbtn').click(doOutput);
});
$(function(){
	// 先将body隐藏，再显示，不会出现页面刷新效果
	$("body").css({visibility:"visible"});
	
	// 收派标准数据表格
	$('#grid').datagrid( {
		iconCls : 'icon-forward',
		fit : true,
		border : false,
		rownumbers : true,
		singleSelect:true,
		striped : true,
		toolbar : '#tb',
		url : "${pageContext.request.contextPath}/page.outputrulerlist.ashx",
		idField : 'rId',
		columns : columns,
		pageList: [30,50,100],
		pagination:true,
		view:myview,
		emptyMsg:"<font size=6>暂无记录</font>"
		/* singleSelect: false,
		selectOnCheck: true,
		checkOnSelect: true		 */ 
	});
	
  

	
	//提交表单
	$('#save').click(function(){
		
		//alert($('#sform').form('validate'))
			// 校验
			if($('#sform').form('validate')){
				// 1 、获得form 数据
				var params = $('#sform').serialize();
				// 2、将数据发送给服务器 
				$.post("${pageContext.request.contextPath}/page.saveChuKuDan.ashx", params , function(data){
					if(data == "success"){
						//alert(1111)
						// 成功
						$.messager.alert('消息','操作成功 ','info');
						// 关闭窗口
						$('#outputWindow').window('close');
						// 清除表单数据
						$('#outputWindow').form('clear');
						$('#outputWindow *').trigger('blur');// 离焦
						
						// 刷新表格数据 
						$('#grid').datagrid('reload');
					}else{
						$.messager.alert('消息','操作失败 ','info');
					}
						
				});
			}
			
		});	
	
	
});



var myview = $.extend({},$.fn.datagrid.defaults.view,{
	onAfterRender:function(target){
		$.fn.datagrid.defaults.view.onAfterRender.call(this,target);
		var opts = $(target).datagrid('options');
		var vc = $(target).datagrid('getPanel').children('div.datagrid-view');
		vc.children('div.datagrid-empty').remove();
		if (!$(target).datagrid('getRows').length){
			var d = $('<div class="datagrid-empty"></div>').html(opts.emptyMsg || 'no records').appendTo(vc);
			d.css({
				position:'absolute',
				left:0,
				top:50,
				width:'100%',
				textAlign:'center'
			});
		}
	}
});

function load(){
	$('#searchcontent_sn').focus();
}

</script>	

</head>
<body class="easyui-layout" onload="load()" >
	<div region="center">
	
		<table id="grid">
		
		</table>
	</div>
	

	
	<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
		
			<!-- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SN: <input onkeydown=keyDown(event)  id="searchcontent" class="easyui-textbox" style="width:180px" > -->
			 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SN: <input  id="searchcontent_sn" class="easyui-textbox" style="width:180px" > 
			 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MAC: <input  id="searchcontent_mac" class="easyui-textbox" style="width:180px" > 
			 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;出库起止时间: <input editable="false"  id="searchcontent_startdate" class="easyui-datebox" style="width:100px"  > ~ <input editable="false"  id="searchcontent_enddate" class="easyui-datebox" style="width:100px" >
			<a href="#"  id="search" class="easyui-linkbutton" iconCls="icon-search">查询</a>
			<a href="#"  id="reset" class="easyui-linkbutton" iconCls="icon-edit">清空查询条件</a>
			
			
		</div>
	</div>
</body>
<script type="text/javascript">
function keyDown(e) {
	var ev= window.event||e;
	//13是键盘上面固定的回车键
	if (ev.keyCode == 13) {
		//你要执行的方法
		doSearch();
	}
} 

</script>
</html>